#pragma once
#include "base/core/os/os_head.h"
#include <sys/types.h>
#include <stddef.h>
#if defined(WIN32)
	typedef     unsigned int    THREAD_ID;
	typedef     HANDLE          THREAD_HANDLE;
	#define INVAILD_THREAD_HANDLE NULL
#else //  defined(OS_LINUX)
	typedef     pid_t           THREAD_ID;
	typedef     pthread_t       THREAD_HANDLE;
	#define INVAILD_THREAD_HANDLE 0u
#endif  // OS

 typedef void fnThreadFunction(void *pvArg);

 class IThreadFunction
 {
 public:
     virtual int ThreadFunction(void *pvArg) = 0;
 };

class Thread 
{
protected:
	THREAD_HANDLE        thread_handle_;
	volatile bool        stop_thread_flag_;
	fnThreadFunction    *m_pfnThread;
	void                *m_pvThreadArg;
	IThreadFunction    *m_pThreadFunction;

public:
    enum THREAD_STOP_TYPE 
	{
        WAIT_SELF_EXIT,
        FORCE_CANCEL
    };

public:
	Thread();
	virtual ~Thread();
	virtual bool RunThread();
	virtual bool RunThread(fnThreadFunction *pfnThread, void *pvArg = NULL);
	virtual bool RunThread(IThreadFunction *pThreadFunction, void *pvArg = NULL);

	virtual int StopThread(THREAD_STOP_TYPE type);
	virtual int ThreadFunction();

public:
	virtual bool  ThreadFrame() {return 0;};
	virtual bool _RunThread();
};

THREAD_ID ThreadId();
